package com.gitee.wsl.logger.format

import com.gitee.wsl.logger.LogFormatter
import com.gitee.wsl.logger.LogLevel
import com.gitee.wsl.logger.LogPrinter
import com.gitee.wsl.logger.format

class SimpleLogFormatter(val options: SimpleLogFormatterOptions = SimpleLogFormatterOptions()) :LogFormatter {
    override fun format(
        level: LogLevel,
        tag: String,
        messageAny: Any?,
        throwable: Throwable?
    ): String = buildString {
        if (options.separator != null) {
            appendLine("${options.separator} ".repeat(13) + "S T A R T" + " ${options.separator}".repeat(13))
        }
        appendLine("""[${level.name}]: ${messageAny}""")

//        val status = log.status
//        if (status != null && options.status) {
//            appendLine("status: ${status.name}")
//        }
//        if (options.source) {
//            appendLine("source: ${log.source}")
//        }
//        if (options.verbose) log.metadata.entries.forEach { (key, value) ->
//            if (key != "source") appendLine("""$key: $value""")
//        }

        if (options.separator != null) {
            appendLine("${options.separator} ".repeat(14) + "E N D" + " ${options.separator}".repeat(14))
        }
    }
}

fun LogPrinter.useSampleFormat(options: SimpleLogFormatterOptions) = format(SimpleLogFormatter(options))

class SimpleLogFormatterOptions(
    val separator: String? = "=",
    val verbose: Boolean = true,
    val status: Boolean = true,
    val source: Boolean = false
)